package com.longcai.piaojia.activity;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.longcai.piaojia.BaseApplication;
import com.longcai.piaojia.R;
import com.longcai.piaojia.adapter.OrderListAdapter;
import com.longcai.piaojia.beans.TicketEntity;
import com.longcai.piaojia.conn.Conn;
import com.longcai.piaojia.conn.ExpressAgeOrderGet;
import com.longcai.piaojia.conn.OrderCouponGet;
import com.longcai.piaojia.conn.OrderIntegralGet;
import com.longcai.piaojia.conn.SubmitOrderPost;
import com.longcai.piaojia.dialog.WarnningDialog;
import com.longcai.piaojia.util.MyToast;
import com.longcai.piaojia.util.UtilPermission;
import com.longcai.piaojia.widget.NoScrollListView;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.glide.GlideLoader;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.scale.ScaleScreenHelperFactory;
import com.zcx.helper.util.UtilApp;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/8/2.
 */
public class SubmitOrderActivity extends BaseActivity implements View.OnClickListener {

    // 配送方式上面的
    @BoundView(R.id.order_title_tv)
    private TextView order_title_tv;
    @BoundView(R.id.order_time_tv)
    private TextView order_time_tv;
    @BoundView(R.id.order_place_tv)
    private TextView order_place_tv;
    @BoundView(R.id.order_address_tv)
    private TextView order_address_tv;
    @BoundView(R.id.submit_order_iv)
    private ImageView submit_order_iv;

    @BoundView(R.id.order_top_order_count_num_tv)
    private TextView order_top_order_count_num_tv;
    @BoundView(R.id.order_top_order_money_tv)
    private TextView order_top_order_money_tv;

    ///
    @BoundView(R.id.order_nslv)
    private NoScrollListView order_nslv;
    @BoundView(R.id.order_dispatching_type_rl)
    private RelativeLayout order_dispatching_type_rl;
    @BoundView(R.id.order_draw_bill_rl)
    private RelativeLayout order_draw_bill_rl;
    @BoundView(R.id.order_integration_check_sel_iv)
    private ImageView order_integration_check_sel_iv;
    @BoundView(R.id.order_draw_bill_check_sel_iv)
    private ImageView order_draw_bill_check_sel_iv;
    @BoundView(R.id.order_integration_check_no_iv)
    private ImageView order_integration_check_no_iv;
    @BoundView(R.id.order_draw_bill_check_no_iv)
    private ImageView order_draw_bill_check_no_iv;
    @BoundView(R.id.submit_order_bottom_submit_tv)
    private TextView submit_order_bottom_submit_tv;

    //这下面  是 上门自提的布局和view
    @BoundView(R.id.dispatching_type_since_rl)
    private LinearLayout dispatching_type_since_rl;
    @BoundView(R.id.dispatching_type_consignee_tv)
    private TextView dispatching_type_consignee_tv;
    @BoundView(R.id.dispatching_type_phone_tv)
    private TextView dispatching_type_phone_tv;
    @BoundView(R.id.dispatching_type_ticket_address_tv)
    private TextView dispatching_type_ticket_address_tv;
    @BoundView(R.id.dispatching_type_title_tv)
    private TextView dispatching_type_title_tv;

    //这是 邮寄的  布局和view
    @BoundView(R.id.dispatching_type_express_ll)
    private LinearLayout dispatching_type_express_ll;
    @BoundView(R.id.dispatching_type_express_name_tv)
    private TextView dispatching_type_express_name_tv;
    @BoundView(R.id.dispatching_type_express_phone_tv)
    private TextView dispatching_type_express_phone_tv;
    @BoundView(R.id.dispatching_type_express_address_tv)
    private TextView dispatching_type_express_address_tv;

    //优惠券
    @BoundView(R.id.order_coupon_number_tv)
    private TextView order_coupon_number_tv;
    @BoundView(R.id.order_coupon_price_tv)
    private TextView order_coupon_price_tv;
    @BoundView(R.id.order_coupon_rl)
    private RelativeLayout order_coupon_rl;

    //积分
    @BoundView(R.id.order_integration_rl)
    private RelativeLayout order_integration_rl;
    @BoundView(R.id.order_integration_tv)
    private TextView order_integration_tv;
    @BoundView(R.id.order_integration_deduction_tv)
    private TextView order_integration_deduction_tv;

    //最下面价格展示
    @BoundView(R.id.submit_order_bottom_price_tv)
    private TextView submit_order_bottom_price_tv;
    @BoundView(R.id.submit_order_bottom_freight_price_tv)
    private TextView submit_order_bottom_freight_price_tv;
    @BoundView(R.id.submit_order_bottom_coupon_price_tv)
    private TextView submit_order_bottom_coupon_price_tv;
    @BoundView(R.id.submit_order_bottom_integral_price_tv)
    private TextView submit_order_bottom_integral_price_tv;
    @BoundView(R.id.submit_order_bottom_total_price_tv)
    private TextView submit_order_bottom_total_price_tv;

    //
    private String getdata;


    private List<TicketEntity> lists = new ArrayList<>();
    private OrderListAdapter orderListAdapter;

    private OrderCouponGet.OrderCouponEntity CouponEntity;
    private OrderIntegralGet.OrderIntegralEntity IntegralEntity;

    private String total_price;//票面总价
    private String discount;//折扣 0.9
    private String truePrice;//实际上的总价 = 票面总价 * 折扣 - 优惠券 - 积分抵扣
    private boolean isIntegral = false;
    private String invoice = "0"; //是否开发票  0 不开 ，1 开
    private String classid;

    //配送方式的三个变量
    private String name;
    private String phone;
    private String address;

    private String sbumit_classid = "";
    private String submit_integral = "";
    private String submit_deduction = ""; //积分提交的变量

    private String mFreightPrice, mcouponPrice, mIntegralPrice;// 邮费 优惠券优惠 积分抵扣的钱

    private String submitCoupon; //优惠券数组  提交用的

//    private StringBuffer seatStr = new StringBuffer();//记录票  几排几号的数组

    private int dispatchingType = 0;

    private boolean isShowDialog;// 判断弹框没显示过

    private boolean isShowPost;// 判断是否现实 快递配送 传到配送方式用  这页不用

    //判断日期  演出日期 是否大于3天 是 成功
    private ExpressAgeOrderGet expressAgeOrderGet = new ExpressAgeOrderGet(new AsyCallBack<String>() {
        @Override
        public void onSuccess(String toast, int type, String s) throws Exception {

            isShowPost = true; //传到配送方式那一页

        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            dispatchingType = 2; //当不大于3天 时候默认选 上门自取  传到配送方式那一页

        }
    });

//    private OrderCouponGet orderCouponGet = new OrderCouponGet(new AsyCallBack<OrderCouponGet.OrderCouponEntity>(){
//
//        @Override
//        public void onSuccess(String toast, int type, OrderCouponGet.OrderCouponEntity orderCouponEntity) throws Exception {
//
//            if (!TextUtils.isEmpty(orderCouponEntity.money)) {
//
//                CouponEntity = orderCouponEntity;
//
//                order_coupon_number_tv.setText(getString(R.string.submit_order_coupon_count_symbols_text)+ orderCouponEntity.number +getString(R.string.submit_order_coupon_count_text));
//                order_coupon_price_tv.setText(getString(R.string.submit_order_coupon_benefit_text)+ orderCouponEntity.money +getString(R.string.goods_info_money_text));
//
//                calculatePrice("0", orderCouponEntity.money);
//
//            } else {
//
//                CouponEntity = orderCouponEntity;
//
//                order_coupon_number_tv.setText("");
//                order_coupon_price_tv.setText("");
//
//                calculatePrice("0", "0");
//
//            }
//
//        }
//
//        @Override
//        public void onFail(String toast, int type) throws Exception {
//
//
//        }
//
//        @Override
//        public void onEnd(String toast, int type) throws Exception {
//            super.onEnd(toast, type);
//
//            //积分
//            orderIntegralGet.user_id = BaseApplication.BasePreferences.readUserId();
//            orderIntegralGet.execute(SubmitOrderActivity.this);
//
//        }
//    });

    private OrderIntegralGet orderIntegralGet = new OrderIntegralGet(new AsyCallBack<OrderIntegralGet.OrderIntegralEntity>() {

        @Override
        public void onSuccess(String toast, int type, OrderIntegralGet.OrderIntegralEntity orderIntegralEntity) throws Exception {

            IntegralEntity = orderIntegralEntity;

            if (!orderIntegralEntity.deduction.equals("0") && !TextUtils.isEmpty(orderIntegralEntity.deduction)) {

                order_integration_rl.setVisibility(View.GONE);

            }

            calculatePrice("0", "0");

//            if(!TextUtils.isEmpty(CouponEntity.money)){//有优惠券的情况
//
//                if (!orderIntegralEntity.deduction.equals("0") && !TextUtils.isEmpty(orderIntegralEntity.deduction)) {
//
//                    order_integration_rl.setVisibility(View.GONE);
//
//                }
//
//                calculatePrice("0", CouponEntity.money);
//
//            }else{
//
//                if (!orderIntegralEntity.deduction.equals("0") && !TextUtils.isEmpty(orderIntegralEntity.deduction)) {
//
//                    order_integration_rl.setVisibility(View.GONE);
//
//                }
//
//                calculatePrice("0", "0");
//
//            }

//            if (!orderIntegralEntity.deduction.equals("0") && !TextUtils.isEmpty(orderIntegralEntity.deduction)) {
//
//                order_integration_rl.setVisibility(View.VISIBLE);
//
//                order_integration_tv.setText(orderIntegralEntity.integral + getString(R.string.mine_count_unit));
//                order_integration_deduction_tv.setText(getString(R.string.submit_order_integral_text) + orderIntegralEntity.deduction + getString(R.string.goods_info_money_text));
//            }

        }

        @Override
        public void onFail(String toast, int type) throws Exception {


        }
    });


    private SubmitOrderPost submitOrderPost = new SubmitOrderPost(new AsyCallBack<String>() {

        @Override
        public void onSuccess(String toast, int type, String s) throws Exception {

            Bundle bundle = new Bundle();

            bundle.putString("truePrice", truePrice);
            bundle.putString("orderNum", s);
            bundle.putString("title", order_title_tv.getText().toString());
            bundle.putString("classid", classid);
            bundle.putBoolean("isOrder", false);
            bundle.putString("orderId", getIntent().getExtras().getString("orderId"));
            bundle.putString("orderNo", getIntent().getExtras().getString("orderNo"));
            bundle.putString("ordertotalAmount", getIntent().getExtras().getString("ordertotalAmount"));
            bundle.putString("is_balance", getIntent().getExtras().getString("is_balance"));
            bundle.putString("postage", mFreightPrice);

            startActivity(new Intent(SubmitOrderActivity.this, PayActivity.class).putExtras(bundle));

            BaseApplication.INSTANCE.finishActivity(GoodsInfoActivity.class, ChooseGoodsActivity.class, SubmitOrderActivity.class);

//            MineFragment.getUserAdvert getUserAdvert = (MineFragment.getUserAdvert) getAppCallBack(MineFragment.class);
//            getUserAdvert.refreshInfo();

        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            MyToast.show(context, toast, Toast.LENGTH_LONG);

        }
    });


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_submit_order);

        String[] permission = {Manifest.permission.CALL_PHONE};
        UtilPermission.Permission(this, permission);


        Bundle bundle2 = getIntent().getExtras();

       // Toast.makeText(context, GoodsInfoActivity.delivery_way, Toast.LENGTH_SHORT).show();

        CouponEntity = new OrderCouponGet.OrderCouponEntity();

        CouponEntity.money = "";
        CouponEntity.number = "";
        CouponEntity.id = "";

        submitCoupon = new JSONArray().toString();

        setBackTrue();

        setTitleName(getResources().getString(R.string.submit_order_title_text));

        order_nslv.setDividerHeight(ScaleScreenHelperFactory.getInstance().getWidthHeight(20));

//        bundle.putString("date", lists_time.get(timeSelectPosition).data);
//        bundle.putString("hour", lists_time.get(timeSelectPosition).hour);
//        bundle.putString("week", lists_time.get(timeSelectPosition).week);
//
//        bundle.putString("money", lists_price.get(priceSelectPosition).money);

        Bundle bundle = getIntent().getExtras();

        order_title_tv.setText(bundle.getString("title"));
        total_price = new BigDecimal(bundle.getString("total_price")).setScale(0, BigDecimal.ROUND_HALF_UP).toString();
        discount = bundle.getString("discount");
        classid = bundle.getString("classid");

        order_time_tv.setText(getString(R.string.item_mycollection_time_text) + bundle.getString("start_time"));
        order_place_tv.setText(getString(R.string.goods_info_show_address_title_text) + bundle.getString("place_name"));
        order_address_tv.setText(getString(R.string.goods_info_show_place_title_text) + bundle.getString("place_address"));
        GlideLoader.getInstance().get(SubmitOrderActivity.this, Conn.IMAGE_BANNER_URL + bundle.getString("picurl"), submit_order_iv, R.mipmap.goods);

        order_top_order_count_num_tv.setText(bundle.getString("goodsCount") + getString(R.string.mybag_ticket_count_text));
        order_top_order_money_tv.setText(total_price + getString(R.string.goods_info_money_text));


//        seatStr.append(bundle.getString("date") + getString(R.string.space) + bundle.getString("week") + getString(R.string.space) + bundle.getString("hour"));
//        for (int i = 0; i < Integer.parseInt(bundle.getString("goodsCount")) - 1; i++) {
//
//            seatStr.append("," + bundle.getString("date") + getString(R.string.space) + bundle.getString("week") + getString(R.string.space) + bundle.getString("hour"));
//
//        }

        if (bundle.getString("is_seat").equals("1")) {

            String content[] = bundle.getString("content").split(",");
            String price[] = bundle.getString("money").split(",");

            for (int i = 0; i < content.length; i++) {

                TicketEntity ticketEntity = new TicketEntity();

                ticketEntity.time = bundle.getString("date") + getString(R.string.space) + bundle.getString("week") + getString(R.string.space) + bundle.getString("season_time");
                ticketEntity.count = content[i];
                ticketEntity.singlePrice = price[i];

                lists.add(ticketEntity);

            }

        } else {

            for (int i = 0; i < 1; i++) {

                TicketEntity ticketEntity = new TicketEntity();

                ticketEntity.time = bundle.getString("date") + getString(R.string.space) + bundle.getString("week") + getString(R.string.space) + bundle.getString("season_time");
                ticketEntity.count = "1" + getString(R.string.mybag_ticket_count_text);
                ticketEntity.singlePrice = bundle.getString("money");

                lists.add(ticketEntity);

            }

        }

        orderListAdapter = new OrderListAdapter(this, lists);
        order_nslv.setAdapter(orderListAdapter);


        //优惠券
//        orderCouponGet.money = bundle.getString("total_price");
//        orderCouponGet.user_id = BaseApplication.BasePreferences.readUserId();
//        orderCouponGet.classid = bundle.getString("classid");
//        orderCouponGet.execute(this);

        orderIntegralGet.user_id = BaseApplication.BasePreferences.readUserId();
        orderIntegralGet.execute(SubmitOrderActivity.this);

        expressAgeOrderGet.time = bundle.getString("date");
        expressAgeOrderGet.execute(SubmitOrderActivity.this);

        order_dispatching_type_rl.setOnClickListener(this);
        order_coupon_rl.setOnClickListener(this);
        order_integration_rl.setOnClickListener(this);
        order_draw_bill_rl.setOnClickListener(this);
        submit_order_bottom_submit_tv.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {

        switch (view.getId()) {

            case R.id.order_dispatching_type_rl:

                Bundle bundle_type = new Bundle();

                bundle_type.putBoolean("isShowPost", isShowPost);
                bundle_type.putInt("dispatchingType", dispatchingType);
                bundle_type.putString("name", name);
                bundle_type.putString("phone", phone);
                bundle_type.putString("address", address);

                bundle_type.putString("place_name", getIntent().getExtras().getString("place_name"));
                bundle_type.putString("place_address", getIntent().getExtras().getString("place_address"));
//配送方式
                Intent intent = new Intent(SubmitOrderActivity.this, DispatchingTypeActivity.class);

                intent.putExtras(bundle_type);

                startActivityForResult(intent, 9);

                break;

            case R.id.order_coupon_rl:

                Bundle bundle = new Bundle();

                bundle.putString("total_price", total_price);
                bundle.putString("classid", getIntent().getExtras().getString("classid"));
//优惠券
                startActivityForResult(new Intent(SubmitOrderActivity.this, OrderCouponActivity.class).putExtras(bundle), 9);

                break;

            case R.id.order_integration_rl:

                if (order_integration_check_sel_iv.getVisibility() == View.INVISIBLE) {

                    isIntegral = true;

                    order_integration_check_sel_iv.setVisibility(View.VISIBLE);
                    order_integration_check_no_iv.setVisibility(View.INVISIBLE);

                    calculatePrice(mFreightPrice, mcouponPrice);

                } else {

                    isIntegral = false;

                    order_integration_check_sel_iv.setVisibility(View.INVISIBLE);
                    order_integration_check_no_iv.setVisibility(View.VISIBLE);

                    calculatePrice(mFreightPrice, mcouponPrice);

                }

                break;

            case R.id.order_draw_bill_rl:

                if (order_draw_bill_check_sel_iv.getVisibility() == View.INVISIBLE) {

                    order_draw_bill_check_sel_iv.setVisibility(View.VISIBLE);
                    order_draw_bill_check_no_iv.setVisibility(View.INVISIBLE);

                    invoice = "1";

                } else {

                    order_draw_bill_check_sel_iv.setVisibility(View.INVISIBLE);
                    order_draw_bill_check_no_iv.setVisibility(View.VISIBLE);

                    invoice = "0";

                }

                break;

            case R.id.submit_order_bottom_submit_tv:

                if (dispatching_type_title_tv.getText().toString().length() < 5) {

                    MyToast.show(context, getString(R.string.dispatching_type_please_choose_text), 2000);
                    return;

                }

                if (!getIntent().getExtras().getString("is_seat").equals("1") && !isShowDialog) {

                    new WarnningDialog(context, getString(R.string.warnning_call_service_text), context.getString(R.string.cancel_text), getString(R.string.call_text)) {
                        @Override
                        protected void onConfirm() {

                            new WarnningDialog(context, BaseApplication.BasePreferences.readNoSeatServiceTel(), context.getString(R.string.cancel_text), context.getString(R.string.confirm_text)) {
                                @Override
                                protected void onConfirm() {

                                    UtilApp.call(context, BaseApplication.BasePreferences.readNoSeatServiceTel());

                                    isShowDialog = true;

                                    return;
                                }
                            }.show();

                        }
                    }.show();

                } else {

                    isShowDialog = true;
                }

                Bundle bundle1 = getIntent().getExtras();

                JSONObject jsonObject = new JSONObject();

                try {

                    jsonObject.put("user_id", BaseApplication.BasePreferences.readUserId());
                    jsonObject.put("show_id", bundle1.getString("goodsInfoId"));
                    jsonObject.put("type", bundle1.getString("is_seat"));//0无座1有座2待定
                    jsonObject.put("ballot", bundle1.getString("goodsCount"));//票张数
                    jsonObject.put("times", bundle1.getString("date") + getString(R.string.space) + bundle1.getString("week") + getString(R.string.space) + bundle1.getString("season_time"));//演出日期 周几 场次 时间
                    jsonObject.put("dateTime", bundle1.getString("performance_time"));//演出日期时间戳
                    jsonObject.put("play_id", bundle1.getString("play_id", ""));//选择价钱的id
                    jsonObject.put("money", bundle1.getString("money")); //单张票的金额
                    jsonObject.put("content", bundle1.getString("content", ""));//"一楼11排26号,一楼11排27号,一楼11排27号", //有座的位置信息无座和预定（语言自己组织）"
                    jsonObject.put("seat_id", bundle1.getString("seat_id", ""));// '1498741, 1498742, 1498709//票座的id没有传''
                    jsonObject.put("status", "0"); //购买状态0未支付1已支付2已使用3退款4过期订单
                    jsonObject.put("invoice", invoice); //开发票1是0否
                    jsonObject.put("total_money", total_price); //票面总价
                    jsonObject.put("discount_price", truePrice); //折后价
                    jsonObject.put("postage", mFreightPrice); //邮费
                    jsonObject.put("orderId", bundle1.getString("orderId", "")); //订单ID - 第三方
                    jsonObject.put("orderNo", bundle1.getString("orderNo", "")); //订单编号 - 第三方
                    jsonObject.put("ordertotalAmount", bundle1.getString("ordertotalAmount", "")); //订单编号 - 第三方
                    jsonObject.put("is_balance", bundle1.getString("is_balance", "")); //惠民卡余额是否可用，0否， 1是
                    jsonObject.put("class_id", bundle1.getString("classid", ""));//演出分类id


                    JSONObject objectTicketInfo = new JSONObject();

                    objectTicketInfo.put("title", bundle1.getString("title"));//标题
                    objectTicketInfo.put("picurl", bundle1.getString("picurl"));//图片
                    objectTicketInfo.put("posttime", bundle1.getString("start_time"));//时间
                    objectTicketInfo.put("place", bundle1.getString("place_name"));//场地
                    objectTicketInfo.put("address", bundle1.getString("place_address"));//场地具体地址


                    JSONObject objectAddress = new JSONObject();

                    objectAddress.put("type", dispatching_type_title_tv.getText().toString());//配送方式-快递
                    objectAddress.put("name", name);//姓名
                    objectAddress.put("address", address);//详细地址
                    objectAddress.put("phone", phone);//手机号

//                    JSONObject objectCoupon = new JSONObject();
//
//                    objectCoupon.put("id", CouponEntity.id);//优惠券ID注意：如果没有传空
//                    objectCoupon.put("money",CouponEntity.money);//钱数注意：如果没有传空''
//                    objectCoupon.put("type", CouponEntity.type);

                    JSONObject objectIntegral = new JSONObject();

                    objectIntegral.put("type", sbumit_classid);//演出分类ID注意：如果没有传空'
                    objectIntegral.put("integral", submit_integral); //使用积分注意：如果没有传空''
                    objectIntegral.put("discount", submit_deduction);//兑换钱数注意：如果没有传空''

                    jsonObject.put("show", objectTicketInfo);
                    jsonObject.put("address", objectAddress);
                    jsonObject.put("coupon", submitCoupon);
                    jsonObject.put("integral", objectIntegral);

                } catch (JSONException e) {
                    e.printStackTrace();
                }

                if (isShowDialog) {

                    submit_order_bottom_submit_tv.setEnabled(false);

                    submitOrderPost.order = jsonObject.toString();


                    submitOrderPost.execute(SubmitOrderActivity.this);
                }

                break;

        }

    }


    public String calculatePrice(String freightPrice, String couponPrice) {//, String integralPrice

        mFreightPrice = freightPrice;
        mcouponPrice = couponPrice;

        BigDecimal orderPrice = new BigDecimal(total_price);

        if (Double.valueOf(total_price) >= 200) {

            mFreightPrice = "0";
            freightPrice = "0";

        }

//        Log.e("---------->", "total_price" + orderPrice.toString() + "freightPrice   " + freightPrice + "couponPrice    "+ couponPrice + "integralPrice "+integralPrice);
//        Log.e("---------->", "BaseApplication.BasePreferences.readIsFavourable()" + discount);

        if (BaseApplication.BasePreferences.readIsFavourable().equals("2") && getIntent().getExtras().getString("is_balance").equals("1")) {//&&getIntent().getExtras().getString("classid").equals("6")

            BigDecimal favour = new BigDecimal(discount);

            orderPrice = orderPrice.multiply(favour);

//            Log.e("---------->", "BaseApplication.BasePreferences.readIsFavourable()" + favour +orderPrice.toString());

        }

        BigDecimal orderFreight = new BigDecimal(freightPrice);
        BigDecimal orderCouponPrice = new BigDecimal(couponPrice);

        BigDecimal orderIntegralPrice;

        if (isIntegral) {

            orderIntegralPrice = new BigDecimal(orderPrice.subtract(orderCouponPrice).toString());

        } else {

            orderIntegralPrice = new BigDecimal("0");

        }

        BigDecimal orderResultPrice = orderPrice.add(orderFreight).subtract(orderCouponPrice).subtract(orderIntegralPrice);

//        DecimalFormat decimalFormat = new DecimalFormat("#.00");

        mIntegralPrice = orderIntegralPrice.setScale(0, BigDecimal.ROUND_HALF_UP) + "";

        truePrice = orderResultPrice.setScale(0, BigDecimal.ROUND_HALF_UP) + "";

        Log.e("---------->", truePrice);

        submit_order_bottom_price_tv.setText(total_price + getString(R.string.goods_info_money_text));
        submit_order_bottom_freight_price_tv.setText(freightPrice + getString(R.string.goods_info_money_text));

        if (couponPrice.equals("0")) {

            submit_order_bottom_coupon_price_tv.setText(couponPrice + getString(R.string.goods_info_money_text));

        } else {

            submit_order_bottom_coupon_price_tv.setText(context.getString(R.string.goods_info_symbols_text) + couponPrice + getString(R.string.goods_info_money_text));

        }

        BigDecimal proportion = new BigDecimal(IntegralEntity.proportion);

        if (!isIntegral) {

            submit_order_bottom_integral_price_tv.setText("0" + getString(R.string.goods_info_money_text));

            sbumit_classid = "";
            submit_integral = "";
            submit_deduction = "";

        } else {

            submit_order_bottom_integral_price_tv.setText(context.getString(R.string.goods_info_symbols_text) + mIntegralPrice + getString(R.string.goods_info_money_text));

            sbumit_classid = getIntent().getExtras().getString("classid");
            submit_integral = Math.round(Float.parseFloat(orderIntegralPrice.divide(proportion).toString())) + "";
            submit_deduction = mIntegralPrice;


        }

        order_integration_tv.setText(Math.round(Float.parseFloat(new BigDecimal(orderPrice.subtract(orderCouponPrice).toString()).divide(proportion).toString())) + "" + getString(R.string.mine_count_unit));
        order_integration_deduction_tv.setText(getString(R.string.submit_order_integral_text) + new BigDecimal(orderPrice.subtract(orderCouponPrice).toString()).setScale(0, BigDecimal.ROUND_HALF_UP) + getString(R.string.goods_info_money_text));

        if (Double.valueOf(truePrice) <= 0) {

            truePrice = "0.01";

        }

        submit_order_bottom_total_price_tv.setText(truePrice + getString(R.string.goods_info_money_text));

        return truePrice;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (data != null) {

//            UtilLog.e("--------", "onactivityresult");
            Bundle bundle = data.getExtras();

            switch (resultCode) {

                case 1:

                    dispatchingType = 1;

                    dispatching_type_title_tv.setText(getString(R.string.myorder_detail_shipping_type_express_text));
                    dispatching_type_since_rl.setVisibility(View.GONE);
                    dispatching_type_express_ll.setVisibility(View.VISIBLE);

                    //TODO 这里写 配送方式-快递带回来的值，view变量 在上面

                    name = bundle.getString("dispatching_type_name_tv");
                    phone = bundle.getString("dispatching_type_tel_tv");
                    address = bundle.getString("dispatching_type_address_tv");

                    dispatching_type_express_name_tv.setText(name);
                    dispatching_type_express_phone_tv.setText(phone);
                    dispatching_type_express_address_tv.setText(address);

                    if (address.contains("道里区") || address.contains("道外区") || address.contains("南岗区") || address.contains("香坊区")) {

                        //5块钱
                        if (!TextUtils.isEmpty(CouponEntity.money)) {//有优惠券的情况
                            calculatePrice("5", CouponEntity.money);
                        } else {
                            calculatePrice("5", "0");
                        }

                    } else {

                        //15块钱
                        if (!TextUtils.isEmpty(CouponEntity.money)) {//有优惠券的情况
                            calculatePrice("15", CouponEntity.money);
                        } else {
                            calculatePrice("15", "0");
                        }

                    }

                    break;

                case 2:

                    dispatchingType = 2;

                    dispatching_type_title_tv.setText(getString(R.string.myorder_detail_shipping_type_since_text));

                    dispatching_type_express_ll.setVisibility(View.GONE);
                    dispatching_type_since_rl.setVisibility(View.VISIBLE);

                    name = bundle.getString("dispatching_type_consignee_tv");
                    phone = bundle.getString("dispatching_type_phone_tv");
                    address = bundle.getString("dispatching_type_ticket_address_tv");

                    dispatching_type_consignee_tv.setText(name);
                    dispatching_type_phone_tv.setText(phone);
                    dispatching_type_ticket_address_tv.setText(address);

//                    UtilLog.e("---------", "" + bundle.getString("dispatching_type_ticket_address_tv"));

                    if (!TextUtils.isEmpty(CouponEntity.money)) {//有优惠券的情况
                        calculatePrice("0", CouponEntity.money);
                    } else {
                        calculatePrice("0", "0");
                    }

                    break;

                case 3:

                    dispatchingType = 3;

                    dispatching_type_title_tv.setText(getString(R.string.myorder_detail_shipping_type_site_exchange_text));
                    dispatching_type_express_ll.setVisibility(View.GONE);
                    dispatching_type_since_rl.setVisibility(View.GONE);

                    //  选择现场取票时候给他们都设置为空

                    name = "";
                    phone = "";
                    address = "";

                    if (!TextUtils.isEmpty(CouponEntity.money)) {//有优惠券的情况
                        calculatePrice("0", CouponEntity.money);
                    } else {
                        calculatePrice("0", "0");
                    }

                    break;

                case 4:

                    // 优惠券回调
                    CouponEntity.money = bundle.getString("money");
                    CouponEntity.id = bundle.getString("id");

                    submitCoupon = bundle.getString("arr");

//                    CouponEntity.type = bundle.getString("type");

//                    Log.e("------>", "CouponEntity.money" + CouponEntity.money);
//                    Log.e("------>", "CouponEntity.id" + CouponEntity.id);

                    if (!TextUtils.isEmpty(CouponEntity.money)) {

                        order_coupon_number_tv.setText(getString(R.string.submit_order_coupon_count_symbols_text) + bundle.getString("count", "") + getString(R.string.submit_order_coupon_count_text));
                        order_coupon_price_tv.setText(getString(R.string.submit_order_coupon_benefit_text) + CouponEntity.money + getString(R.string.goods_info_money_text));

                        calculatePrice(mFreightPrice, CouponEntity.money);
                    } else {

                        order_coupon_number_tv.setText("");
                        order_coupon_price_tv.setText("");

                        calculatePrice(mFreightPrice, "0");

                    }

                    break;

                case 5:

                    dispatchingType = 0;

                    dispatching_type_title_tv.setText(getString(R.string.myorder_detail_shipping_type_text));
                    dispatching_type_since_rl.setVisibility(View.GONE);
                    dispatching_type_express_ll.setVisibility(View.GONE);

                    name = "";
                    phone = "";
                    address = "";

                    if (!TextUtils.isEmpty(CouponEntity.money)) {//有优惠券的情况
                        calculatePrice("0", CouponEntity.money);
                    } else {
                        calculatePrice("0", "0");
                    }

                    break;

            }

        } else {

            Log.e("onactivityresult---->", "如果点击返回为空没有事，不是点击返回 就有毛病了");

        }


    }


}
